package priv.pront.code.national.acwing.search.dfs;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-27 22:10
 */
public class Acwing1113_红与黑 {


    static final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
    static int N = 30;
    static char[][] arr = new char[N][N];
    static int[][] dicts = {
            {-1, 0},
            {0, -1},
            {1, 0},
            {0, 1}
    };

    public static void main(String[] args)throws Exception {
        while (true) {
            String[] s = cin.readLine().split(" ");
            int m = Integer.parseInt(s[0]);
            int n = Integer.parseInt(s[1]);
            //停止读入
            if (n == 0 && m == 0) break;
            //初始化空间
            int x = 0, y = 0;
            for (int i = 0; i < n; i++) {
                String str = cin.readLine();
                for (int j = 0; j < m; j++) {
                    arr[i][j] = str.charAt(j);
                    if (arr[i][j] == '@') {
                        x = i;
                        y = j;
                    }
                }
            }
            System.out.println(dfs(n, m, x, y, new boolean[n][m]));
        }
    }

    public static int dfs(int n, int m, int i, int j, boolean[][] visited) {
        //越界情况
        if (i < 0 || j < 0 || i >= n || j >= m) {
            return 0;
        }
        //遇到红色瓷砖停止
        if (arr[i][j] == '#' || visited[i][j]) return 0;
        int res = 1;
        visited[i][j] = true;
        //四个方向
        for (int d = 0; d < dicts.length; d++) {
            int x = i + dicts[d][0];
            int y = j + dicts[d][1];
            res += dfs(n, m, x, y, visited);
        }
        return res;
    }
}
